package com.shop.milk_tea_shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.milk_tea_shop.common.CodeEnum;
import com.shop.milk_tea_shop.common.GlobalInfo;
import com.shop.milk_tea_shop.common.PageInfo;
import com.shop.milk_tea_shop.common.Result;
import com.shop.milk_tea_shop.entity.EmployeeInfo;
import com.shop.milk_tea_shop.entity.ShopInfo;
import com.shop.milk_tea_shop.mapper.ShopInfoMapper;
import com.shop.milk_tea_shop.request.ShopQueryRequest;
import com.shop.milk_tea_shop.service.ShopInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 店铺信息表：	和店长一一对应，店长登陆即可管理开店 服务实现类
 * </p>
 *
 * @author yjw
 * @since 2024-06-16
 */
@Service
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService {

    @Autowired
    private ShopInfoMapper shopInfoMapper;

    @Override
    public Result<List<ShopInfo>> paged(ShopQueryRequest request) {
        LambdaQueryWrapper<ShopInfo> queryWrapper  = new LambdaQueryWrapper<>();

        queryWrapper.eq(request.getShopId() != null, ShopInfo::getShopId, request.getShopId());
        queryWrapper.eq(request.getStatus() != null, ShopInfo::getStatus, request.getStatus());
        queryWrapper.like(StringUtils.isNotBlank(request.getAddress()), ShopInfo::getAddress, request.getAddress());
        queryWrapper.eq(request.getManagerId() != null, ShopInfo::getManagerId, request.getManagerId());

        Page<ShopInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        Page<ShopInfo> pageResult = shopInfoMapper.selectPage(page, queryWrapper);

        PageInfo pageInfo = new PageInfo(pageResult.getCurrent(), pageResult.getSize(), pageResult.getTotal());
        GlobalInfo globalInfo = new GlobalInfo(pageInfo);
        return new Result<>(CodeEnum.SUCCESS.getMsg(), CodeEnum.SUCCESS, pageResult.getRecords(), globalInfo);
    }
}
